<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <%@include file="/WEB-INF/pages/common/head.jsp"%>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="panel-group col-md-4">
            <label for="loginName">申领单号:</label>
            <input type="text" id="loginName" name="applyMasterNo" class="form-control" value="${applyMasterNo}"  readonly="readonly"/>
        </div>
        <div class="panel-group col-md-4">
            <label>经费来源:</label>
            <select name="applySource" id="applySource" class="form-control">
                <option value="0">科室白支票</option>
                <option value="1">科研经费</option>
            </select>
        </div>
    </div>
    <table id="table" data-toggle="table"
           data-pagination="true"
           data-side-pagination="server"
           data-url="apply/handApply/searchByApplyChild?applyMasterNo=${applyMasterNo}"
           data-toolbar-algin="right"
           data-align="center"
    >
        <thead>
        <tr>
            <th data-field="applyChildId">序号</th>
            <th data-field="cgCode">物资编码</th>
            <th data-field="dictionary.cgName">物资名称</th>
            <th data-field="dictionary.spec">最小规格</th>
            <th data-field="dictionary.unit">包装单位</th>
            <th data-field="dictionary.type" data-formatter="FormatType">物资类别</th>
            <th data-field="applyChildNum">数量</th>
            <th data-formatter="FormatOperation">操作</th>
        </tr>
        </thead>
    </table>
    <div class="row">
        <div class="col-md-8"></div>
        <div class="col-md-3">
            <button class="btn btn-default" onclick="Ming(0)">暂存</button>&nbsp;&nbsp;
            <button class="btn btn-default" onclick="Ming(1)">提交</button>&nbsp;&nbsp;
            <button class="btn btn-default" onclick="location.href='apply/handApply/index'">返回</button>
        </div>
    </div>

    <hr>
    <div id="Dictionary">
        <form id="DictionaryForm"  class="form-horizontal">
            <div class="row">

                <div class="form-group col-md-6">
                    <label for="">物资名称:</label>
                    <input type="text"  name="cgName" class="form-control" readonly="readonly"/>
                    <input type="hidden" name="applyChildId" class="form-control"/>
                </div>

                <div class="form-group col-md-6">
                    <label for="">物资编码:</label>
                    <input type="text"  name="cgCode" class="form-control" readonly="readonly"/>
                </div>
            </div>
            <div class="row">
                <div class="form-group col-md-6">
                    <label for="">最小规格:</label>
                    <input type="text" class="form-control" name="spec" readonly="readonly">
                </div>

                <div class="form-group col-md-6">
                    <label for="">包装单位:</label>
                    <input type="text" class="form-control" name="packUnit" readonly="readonly">
                </div>
            </div>
            <div class="row">

                <div class="form-group col-md-6">
                    <label for="">物资类别:</label>
                    <input type="text" class="hidden" name="type" readonly="readonly">
                    <input type="text" class="hidden" name="gooallCode" readonly="readonly">
                    <input type="text" class="form-control" name="type1" readonly="readonly">
                </div>
                <div class="form-group col-md-6">
                    <label for="">物资数量:</label>
                    <input type="text" class="form-control" name="applyChildNum">
                </div>
            </div>
            <div class="row">
                <div class="col-md-8">
                </div>
                <div class="col-md-4">
                    <button type="button" class="btn btn-default" onclick="xuanzewuzi()">选择物资</button>&nbsp;
                    <button type="button" class="btn btn-default" id="bc" onclick="baocun()">保存</button>
                    <button type="button" class="btn btn-default hidden" id="xg" onclick="xiugai()">修改</button>
                </div>
            </div>


        </form>
    </div>
</div>


<div class="hidden" id="Add">
    <div class="container-fluid">
        <div class="panel panel-info">
            <div class="panel-heading">
                <h4>查询条件</h4>
                <a class="caret pull-right" data-toggle="collapse" href="#content1"></a>
            </div>
            <div id="content1" class="panel-collapse collapse in">
                <div class="panel-body">
                    <form id="condition1"  class="form-inline">
                        <div class="row">
                            <div class="panel-group col-md-6">
                                <label for="cgName">物资名称:</label>
                                <input type="text" id="cgName" name="cgName" class="form-control"/>

                            </div>
                            <div class="panel-group col-md-6">
                                <label for="cgCode">物资编码:</label>
                                <input type="text" id="cgCode" name="cgCode" class="form-control"/>
                            </div>
                        </div>


                        <div class="row">
                            <div class="panel-group col-md-6">
                                <label for="inputCode">助记码:</label>
                                <input type="text" id="inputCode" name="inputCode" class="form-control"/>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-10"></div>
                            <div class="col-md-2">
                                <button class="btn btn-primary" type="button" onclick="searchTjDictionary()">查询</button>
                            </div>

                        </div>

                    </form>
                </div>
            </div>
        </div>

        <table id="table1" data-toggle="table"
               data-pagination="true"
               data-side-pagination="server"
               data-url="base/dictionary/searchByDictionaryPager"
               data-align="center"
        >
            <thead>
            <tr>
                <th data-radio="true"></th>
                <th data-field="dictionaryId">序号</th>
                <th data-field="cgCode">物资编码</th>
                <th data-field="cgName">物资名称</th>
                <th data-field="spec">最小规格</th>
                <th data-field="packUnit">包装单位</th>
                <th data-field="factory" >生产厂家</th>
                <th data-field="sortCode" class="hidden"></th>
                <th data-field="branchCode"  class="hidden"></th>
                <th data-field="warehouseCode"  class="hidden"></th>
            </tr>
            </thead>
        </table>
    </div>



</div>
<%@include file="/WEB-INF/pages/common/modal.jsp"%>
<script src="res/js/upHandApply.js"></script>
<script>
    function baocun(){
        var params=$("#DictionaryForm").serializeArray();
        var param="";
        for(var i in params){

            if(i==params.length-1){
                param+=params[i].name+"="+params[i].value;
            }else{
                param+=params[i].name+"="+params[i].value+"&";
            }
        }
        param=param+"&no="+'${applyMasterNo}'+"&applySource="+$("#applySource").val();
        console.info(param)


       $.post("apply/handApply/add",param,function (msg) {
            $("#table").bootstrapTable("refresh");
            toastr.warning("信息提示",msg);
        },"text")
    }

    function xiugai(){
        var params=$("#DictionaryForm").serializeArray();
        var param="";
        for(var i in params){

            if(i==params.length-1){
                param+=params[i].name+"="+params[i].value;
            }else{
                param+=params[i].name+"="+params[i].value+"&";
            }
        }
        console.info(param)


        $.post("apply/handApply/update",param,function (msg) {
            $("#table").bootstrapTable("refresh");
            toastr.warning("信息提示",msg);
        },"text")
    }

    function Ming(i) {
        if(i==0){
            /*暂存*/
            location='apply/handApply/index'
        }else {
            /*提交*/
            var param="applyMasterNo="+'${applyMasterNo}';
            $.post("apply/handApply/TiJiao",param,function (msg) {
                swal({title:msg,
                    type:"success",confirmButtonText:"OK"}
                    ).then(
                    function(isConfirm) {
                        if(isConfirm){
                            location='apply/handApply/index'
                        }
                    }
                )
            },'text')

        }
    }
</script>
</body>
</html>